package com.kuangstudy.io.serialization;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: Demo3
 * date: 2021/07/16 22:52:00
 *
 * @author zlk
 */
public class Demo3 {
    public static void main(String[] args) throws Exception {
        List<Person> list = new ArrayList<>();
        list.add(new Person("kk1",12));
        list.add(new Person("kk2",12));
        list.add(new Person("kk3",12));
        list.add(new Person("kk4",12));
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("e:\\person.txt"));
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("e:\\person.txt"));
        oos.writeObject(list);
        List<Person> list1 = (List<Person>) ois.readObject();
        for (Person person : list1) {
            System.out.println(person);
        }
        oos.close();
        ois.close();
    }
}
